package XmlNetty;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChildChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

public class byteToXmlClientHandle extends SimpleChannelHandler {

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		// TODO Auto-generated method stub
		XmlPackge xmlpackge = (XmlPackge) e.getMessage();
		String jdxh = xmlpackge.getJdxh();
		
		if("connectioned".equals(jdxh)){
			xmlpackge = new XmlPackge("example/Config.xml", new byte[0]);
			e.getChannel().write(xmlpackge);
			return;
		}
		System.out.println(xmlpackge.getBfile());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
		// TODO Auto-generated method stub
		e.getCause().printStackTrace();
		e.getChannel().close();
	}
}
